using System;
using FireStarter.Base;
using FireStarterModeller.BO;
using Habanero.Base.Exceptions;
using Habanero.BO;
using NUnit.Framework;

namespace FireStarterModeller.Test.BO
{
    /// <summary>
    /// Provides a place to write custom tests for DMPropRuleParameter objects.
    /// This file is only written once and can be changed.  The Def file
    /// attached to this as a dependent is rewritten with each regeneration
    /// and contains the standard tests for DMPropRuleParameter.
    /// Regenerate this test project whenever there have been changes to the
    /// business objects.
    /// If tests are failing due to a unique setup in your application,
    /// you can either override the Create methods in TestUtils, or you
    /// can add the test to the ignore list below and reimplement it here.
    /// </summary>
    public partial class TestDMPropRuleParameter
    {
        [TestFixtureSetUp]
        public void SetupTestFixture()
        {
            //------------------------------------------------------------
            // Use this list to ignore generated tests that are failing
            // due to a unique condition in your application.
            // Remember to reimplement the test here.
            //------------------------------------------------------------
            //_ignoreList.Add("TestMethodName", "Reason for ignoring it");
            base.SetupFixture();
        }

        [Test]
        public void Test_ToString()
        {
            //---------------Set up test pack-------------------
            DMPropRuleParameter dmPropRuleParameter = TestUtilsDMPropRuleParameter.CreateUnsavedValidDMPropRuleParameter();
            //---------------Assert Precondition----------------
            Assert.IsFalse(String.IsNullOrEmpty(dmPropRuleParameter.KeyName), "KeyName Should not be null");
            //---------------Execute Test ----------------------
            string actualToString = dmPropRuleParameter.ToString();
            //---------------Test Result -----------------------
            Assert.AreEqual(dmPropRuleParameter.KeyName, actualToString);
        }
        [Test]
        public void Test_ToString_KeyNull()
        {
            //---------------Set up test pack-------------------
            DMPropRuleParameter dmPropRuleParameter = TestUtilsDMPropRuleParameter.CreateUnsavedValidDMPropRuleParameter();
            dmPropRuleParameter.KeyName = null;
            //---------------Assert Precondition----------------
            Assert.IsTrue(String.IsNullOrEmpty(dmPropRuleParameter.KeyName), "KeyName Should be null");
            //---------------Execute Test ----------------------
            string actualToString = dmPropRuleParameter.ToString();
            //---------------Test Result -----------------------
            Assert.AreEqual(dmPropRuleParameter.PropRuleParameterID.ToString(), actualToString);
        }
        [Test]
        public void Test_ToString_KeyNull_PropRuleParameterIDNull()
        {
            //---------------Set up test pack-------------------
            DMPropRuleParameter dmPropRuleParameter = TestUtilsDMPropRuleParameter.CreateUnsavedValidDMPropRuleParameter();
            dmPropRuleParameter.KeyName = null;
            dmPropRuleParameter.PropRuleParameterID = null;
            //---------------Assert Precondition----------------
            Assert.IsTrue(String.IsNullOrEmpty(dmPropRuleParameter.KeyName), "KeyName Should be null");
            Assert.IsNull(dmPropRuleParameter.PropRuleParameterID);
            //---------------Execute Test ----------------------
            string actualToString = dmPropRuleParameter.ToString();
            //---------------Test Result -----------------------
            Assert.AreEqual("-unnamed PropRule-", actualToString);
        }
        [Test]
        public void Test_GetParent()
        {
            //---------------Set up test pack-------------------
            DMPropRule propRule = new DMPropRule();
            DMPropRuleParameter param = new DMPropRuleParameter();
            propRule.PropRuleParameters.Add(param);
            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            IModelElement parent = ((IModelElement)param).Parent;
            //---------------Test Result -----------------------
            Assert.AreSame(propRule, parent);
        }

        [Test]
        public void Test_SetParentExceptionThrown()
        {
            //---------------Set up test pack-------------------
            IModelElement param = new DMPropRuleParameter();

            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            Exception exceptionThrown = null;
            try
            {
                param.Parent = new DMPropRule();
            }
            catch (Exception ex)
            {
                exceptionThrown = ex;
            }
            //---------------Test Result -----------------------
            Assert.IsNotNull(exceptionThrown);
            Assert.IsInstanceOf(typeof(HabaneroDeveloperException), exceptionThrown);
            StringAssert.Contains
                ("Set the parent of the Property rule parameter by setting the related Property rule object",
                 exceptionThrown.Message);
        }

        [Test]
        public void Test_ChangeValue_WhenDMPropNotNull_AndDMPropTypeNull_ShouldNotRaiseError_FixBug()
        {
            //---------------Set up test pack-------------------
            var propRuleParam = new DMPropRuleParameter();
            var propRule = TestUtilsDMPropRule.CreateUnsavedValidDMPropRule();
            var dmProperty = propRule.DMProperty;
            dmProperty.PropertyType = null;
            propRuleParam.PropRule = propRule;
            //---------------Assert Precondition----------------
            Assert.IsNotNull(propRuleParam.PropRule);
            Assert.IsNotNull(propRuleParam.PropRule.DMProperty);
            Assert.IsNull(propRuleParam.PropRule.DMProperty.PropertyType);
            //---------------Execute Test ----------------------
            propRuleParam.Value = Habanero.Testability.RandomValueGen.GetRandomString();
            //---------------Test Result -----------------------
            Assert.IsTrue(true, "If it got here all is good");
        }
    }
}